package com.sdsy.blockchaintrainingback.controller.training;

import com.sdsy.blockchaintrainingback.context.ThreadLocalContextHolder;
import com.sdsy.blockchaintrainingback.pojo.common.CommonResult;
import com.sdsy.blockchaintrainingback.pojo.training.TrainingEnvRelation;
import com.sdsy.blockchaintrainingback.pojo.training.UserTraining;
import com.sdsy.blockchaintrainingback.service.training.UserTrainingService;
import com.sdsy.blockchaintrainingback.vo.training.ResetContainerVo;
import com.sdsy.blockchaintrainingback.vo.training.RestartContainerVo;
import com.sdsy.blockchaintrainingback.vo.training.SaveAnswerReportVo;
import com.sdsy.blockchaintrainingback.vo.training.UserTrainingRespVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import static com.sdsy.blockchaintrainingback.pojo.common.CommonResult.success;

/**
 * @Description TODO
 * @Author linzili
 * @Date 2023/9/26 23:07
 * @Version 1.0
 */
@RestController
@RequestMapping("/user_training")
public class UserTrainingController {

    @Resource
    private UserTrainingService userTrainingService;

    @GetMapping("/start")
    public CommonResult<UserTrainingRespVo> startTraining(Integer trainingId) {
        return success(userTrainingService.startTraining(ThreadLocalContextHolder.getUserId(),trainingId));
    }

    @PostMapping("/save_answer_report")
    public CommonResult<Boolean> saveAnswerRepost(@RequestBody SaveAnswerReportVo vo) {
       userTrainingService.saveAnswerReport(vo);
       return success(true);
    }

    @PostMapping("/restart_container")
    public CommonResult<Boolean> restartContainer(@RequestBody RestartContainerVo vo ) {
        userTrainingService.restartContainer(vo.getUserTrainingId());
        return  success(true);
    }

    @PostMapping("/reset_container")
    public CommonResult<Boolean> resetContainer(@RequestBody ResetContainerVo vo) {
        userTrainingService.resetContainer(vo.getUserTrainingId());
        return  success(true);
    }
}
